package com.bort.system.controller.admin;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileInputStream;

@Controller
public class AdminViewController {

    @Value("${uploadRootPath:D:/workspace/bort/images/}")
    private String root;

    @RequestMapping({"/index",""})
    public String index(){
        return "index";
    }

    @RequestMapping(value = "/image",produces = MediaType.IMAGE_JPEG_VALUE)
    @ResponseBody
    public byte[] image(@RequestParam("path") String path) throws Exception {
        File file = new File(root+path);
        try(FileInputStream inputStream = new FileInputStream(file)){
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes, 0, inputStream.available());
            return bytes;
        }
    }

    @RequestMapping("/mobile")
    public String mobile(){
        return "mobile";
    }

}
